package com.clkj.sunhelp.mvp.projkindchoose;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.adapter.list.ListAdapterForProjKindChoose;
import com.clkj.sunhelp.app.CustomApplication;
import com.clkj.sunhelp.bean.HelpProjKindItem;
import com.clkj.sunhelp.common.IntentKey;
import com.clkj.sunhelp.common.RequestAndResultCode;
import com.clkj.sunhelp.mvp.base.BaseActivity;
import com.clkj.sunhelp.mvp.jobdeal.jobkindchoose.JobKindChooseContract;
import com.clkj.sunhelp.mvp.jobdeal.jobkindchoose.JobKindChoosePresenter;
import com.clkj.sunhelp.util.ToastUtil;
import com.clkj.sunhelp.util.schedulers.SchedulerProvider;

import java.util.ArrayList;
import java.util.List;

/**项目类型选择
 * Created by Administrator on 2017/3/29.
 */

public class ActivityChooseProKind extends BaseActivity implements JobKindChooseContract.View {

    //private GridView gv;
    private ListView lv;




    List<HelpProjKindItem> mProKindList = new ArrayList<>();

    //GridAdapterForJobDealKindChoose mAdapter;
    ListAdapterForProjKindChoose mAdapter;
    JobKindChooseContract.Presenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_proj_kind_choose);
        initTitleWithRightTvOrIv(null, null, "项目类型选择", true, null, null);
        initData();
        assignView();
        initView();

        mPresenter = new JobKindChoosePresenter(this, SchedulerProvider.getInstance(), CustomApplication.getInstance().getHttpService());
        getJobKind();
    }

    @Override
    public void initData() {

    }

    @Override
    public void assignView() {

        //gv = (GridView) findViewById(R.id.gv);
        lv = (ListView) findViewById(R.id.lv);
    }

    @Override
    public void initView() {
        //mAdapter = new GridAdapterForJobDealKindChoose(this, mProKindList);

        mAdapter = new ListAdapterForProjKindChoose(this,mProKindList);
        lv.setAdapter(mAdapter);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent backProjKind = new Intent();

                backProjKind.putExtra(IntentKey.INTENT_KEY_PROJ_KIND,mProKindList.get(position));
                setResult(RequestAndResultCode.RESULT_CODE_TO_CHOOSE_PROJ_KIND_SUCCESS,backProjKind);
                finish();
            }
        });

       /* gv.setAdapter(mAdapter);
        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent backProjKind = new Intent();

                backProjKind.putExtra(IntentKey.INTENT_KEY_PROJ_KIND,mProKindList.get(position));
                setResult(RequestAndResultCode.RESULT_CODE_TO_CHOOSE_PROJ_KIND_SUCCESS,backProjKind);
                finish();
            }
        });*/
    }

    @Override
    public void getJobKind() {
        mPresenter.getJobKind();
    }

    @Override
    public void onGetJobKindSuccess(List<HelpProjKindItem> helpKindList) {
        mProKindList.clear();
        mProKindList.addAll(helpKindList);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onGetJobKindError(String tip) {
        ToastUtil.showShort(this, tip);
    }

    @Override
    public void setPresenter(JobKindChooseContract.Presenter presenter) {

    }

    @Override
    public void showLoading() {
        showProgressDialog(false, null);
    }

    @Override
    public void dismissLoading() {
        dismissProgressDialog();
    }
}
